<?php

class MY_Controller extends CI_Controller {

	public function montaSelectEstados($default = 13,$disabled=''){
	  
	  
	  $consultaMunicipio = "select * from estado order by sigla"; 
	  $queryMunicipio = $this->db->query($consultaMunicipio);
	  $data['estado'] ="
	    <select name = 'uf' id = 'uf' onchange = 'montaSelectMunicipio()' {$disabled}>
	      <option value = '0'>SELECIONE</option>
	  ";
	  foreach ($queryMunicipio->result() as $row)
	  {
	    $data['estado'] .= ($row->id == $default)?"
	      <option value = '{$row->id}' selected>{$row->sigla}</option>":"
	      <option value = '{$row->id}'>{$row->sigla}</option>"; 
	  }  
	  $data['estado'] .= "</select>";
	  return $data['estado'];
	}
	public function montarSelectMunicipios($estado = 13,$default = 0,$disabled=''){
	  
	  $estado = (isset($_POST['uf']))? $_POST['uf']: $estado;
	  
	  $consultaMunicipio = "select * from municipio where estado = {$estado} order by descricao"; 
	  $queryMunicipio = $this->db->query($consultaMunicipio);
	  $data['municipio'] ="
	    <select name = 'municipio' id = 'municipio' {$disabled}>
	      <option value = '0'>SELECIONE</option>
	  ";
	  foreach ($queryMunicipio->result() as $row)
	  {
	    //$data['municipio'] .= "
	      //<option value = '{$row->id}' ".($row->id == $default)?" selected":"".">{$row->descricao}</option>"; 
	      $data['municipio'] .= ($row->id == $default)?"
	      <option value = '{$row->id}' selected>{$row->descricao}</option>":"
	      <option value = '{$row->id}'>{$row->descricao}</option>"; 
	  }  
	  $data['municipio'] .= "</select>";
	  if (isset ($_POST['uf']))
	    echo $data['municipio'];
	  else
	    return $data['municipio'];
	}
	public function montaMenu(){
	  $this->load->model('perfil_model');
	  $a = $this->session->userdata('user_id');
	  $query = $this->perfil_model->pesquisa_perfil($a);
	  $menu = 'a';
	  $retorno = '<ul>';
	  foreach ($query->result() as $row){
	    $retorno.= ($menu != $row->menu)?(($menu == 'a')?"<li id ='menu-{$row->menu}' onmouseover = 'montamenu(this.id)' onmouseout = 'fechamenu(this.id)'>{$row->nome_menu}<ul style= 'display: none;' id ='itemmenu-{$row->menu}'>":
	      "</ul></li><li id ='menu-{$row->menu}' onmouseover = 'montamenu(this.id)' onmouseout = 'fechamenu(this.id)'>{$row->nome_menu}<ul style= 'display: none;' id ='itemmenu-{$row->menu}'>"):"";
	    $retorno.="<li><a href = '".  base_url()."index.php/{$row->script}'>{$row->nome_tela}</a></li>";
	    $menu=$row->menu;  
	  }
	  $retorno.= "</ul></li></ul><button onclick = 'sair()'>SAIR</button>";
	  return $retorno;
	}
	public function tiraCaracter($str){
	  $str = str_replace('-', '', $str);
	  $str = str_replace('/', '', $str);
	  $str = str_replace('\'', '', $str);
	  $str = str_replace('\"', '', $str);
	  $str = str_replace(',', '', $str);
	  $str = str_replace('.', '', $str);
	  $str = str_replace(':', '', $str);
	  return $str;
	}
}
?>
